﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WS.EKA.Model;

namespace WS.EKA.ServiceImpl
{
    public class ProductCaculateService
    {
        public decimal CaculateDeliveryCosts(int productID, int count, decimal productWeight)
        {
            bool isUse = true;
            string noUseDispatchPrice = "0.00";
            string dispatchPrice = "0.00";
            ////get by produtID
            //produtID->[DispatchMode]->DispatcherRegion list
            List<DispatcherRegion> regions = null;
            foreach (var dispatcherRegion in regions)
            {
                if (dispatcherRegion.ItemCode == "Q")
                {
                    if (Convert.ToDecimal(dispatcherRegion.ItemValue) >= Convert.ToDecimal(productWeight * count))
                    {
                        //不使用公式计算
                        isUse = false;
                    }
                }
                if (dispatcherRegion.ItemCode == "P")
                {
                    //不使用公式时候的配送费用
                    noUseDispatchPrice = dispatcherRegion.ItemValue;
                }
            }
            //get buy productid
            DispatcherMode dispatcherMode = null;
            if (isUse)
            {
                string strFormula = dispatcherMode.Formula;
                foreach (var dispatcherRegion in regions)
                {
                    if (dispatcherRegion.ItemCode.ToUpper() != "W")
                    {
                        strFormula = strFormula.Replace(dispatcherRegion.ItemCode, dispatcherRegion.ItemValue);
                    }
                }
                //计算商品的总重量
                //商品的总重量（替换到w中,都是以克计算）
                strFormula = strFormula.Replace("W", (productWeight * count).ToString());
                //计算配送价格
                //ShopNum1_Common_Action commonAction = (ShopNum1_Common_Action)LogicFactory.CreateShopNum1_Common_Action();
                dispatchPrice = "1000";// commonAction.ComputeDispatchPrice(strFormula);
            }
            //不使用
            else
            {
                dispatchPrice = noUseDispatchPrice;
            }
            return Convert.ToDecimal(dispatchPrice);
        }

        public decimal CaculatePackAndBlessCardCost(Guid orderid)
        {
            //根据orderid获取
            OrderInfo order = null;
            return Decimal.Add(order.PackPrice,order.BlessCardPrice);
        }

        public decimal CaculateDeposit(string memLoginID)
        {
            //[ShopNum1_Member]  AdvancePayment
            //get current user AdvancePayment
            return 0;
        }

    }


    public class DispatcherRegion
    {
        public string ItemCode { get; set; }
        public string ItemValue { get; set; }
    }

    public class DispatcherMode
    {
        public Guid Guid { get; set; }
        public string Formula { get; set; }
    }

    public class OrderInfo
    {
        public Guid Guid { get; set; }
        public Guid PackGuid { get; set; }
        public Guid BlessCardGuid { get; set; }
        public decimal PackPrice { get; set; }
        public decimal BlessCardPrice { get; set; }
    }
}
